﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using ElGee.Google.Charts;
using System.Web.Script.Serialization;

namespace WebApp.GeoMapSample
{
    /// <summary>
    /// Summary description for DataSource
    /// </summary>
    public class DataSource : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            // No Cache, because need fresh values !
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            // Set the content type and encoding for JSON
            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;

            // Find the Construction of the DataSource in /Data/GeoMapData
            GeoMap lc = GeoMapData.GetOptions();

            ChartDataSource cds = GeoMapData.GetDataSource();

            // Create the object needed for All Asynchronous calls. Must be a GeoMapDataSource
            GeoMapDataSource ds = new GeoMapDataSource(cds, lc);

            // Returning the object in JSON Format
            context.Response.Write(new JavaScriptSerializer().Serialize(ds));
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}